package com.atguigu.gulimall.product.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.atguigu.gulimall.product.dao.SpuInfoDescDao;
import com.atguigu.gulimall.product.entity.SpuInfoDescEntity;
import com.atguigu.gulimall.product.service.SpuInfoDescService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("spuInfoDescService")
public class SpuInfoDescServiceImpl extends ServiceImpl<SpuInfoDescDao, SpuInfoDescEntity> implements SpuInfoDescService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpuInfoDescEntity> page = this.page(
                new Query<SpuInfoDescEntity>().getPage(params),
                new QueryWrapper<SpuInfoDescEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveDecript(Long spuId, List<String> decript) {
        if (decript.size()==0 || decript==null){

        }else {
//            List<SpuInfoDescEntity> collect = decript.stream().map(item -> {
//                SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
//                spuInfoDescEntity.setSpuId(spuId);
//                spuInfoDescEntity.setDecript(item);
//                return spuInfoDescEntity;
//            }).collect(Collectors.toList());
//            this.saveBatch(collect);
            SpuInfoDescEntity spuInfoDescEntity = new SpuInfoDescEntity();
            spuInfoDescEntity.setSpuId(spuId);
            String join = String.join(",", decript);
            spuInfoDescEntity.setDecript(join);
            this.save(spuInfoDescEntity);
        }
    }

}